<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  props: {
    info: { type: Object, required: true },
    color: { type: String, default: "#333333" },
    isLock: Boolean,
  },
});
</script>

<template>
  <view class="chapter-item">
    <view class="chapter-item-content">
      <view class="chapter-item-name" :style="{ color }">
        {{ info.title }}
      </view>
      <view style="display: flex; align-items: center">
        <template v-if="isLock">
          <view class="chapter-item-listen" v-if="info.canListen">试听</view>
          <view class="chapter-item-state" v-else>解锁</view>
        </template>
        <view class="chapter-item-time">{{ info.duration }}</view>
      </view>
    </view>

    <slot />
  </view>
</template>

<style lang="scss">
.chapter-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 30rpx;

  .chapter-item-content {
    flex-grow: 1;
    min-width: 0;
  }

  .chapter-item-name {
    margin-bottom: 20rpx;
    font-size: 28rpx;
    line-height: 36rpx;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .chapter-item-listen,
  .chapter-item-state {
    padding: 0 6rpx;
    margin-right: 10rpx;
    font-size: 20rpx;
    color: #faad14;
    line-height: 28rpx;
    background-color: rgba(250, 173, 20, 0.1);
  }

  .chapter-item-state {
    color: #999999;
    background-color: rgba(153, 153, 153, 0.07);
  }

  .chapter-item-time {
    font-size: 22rpx;
    color: #999999;
    line-height: 32rpx;
  }
}
</style>